<script>
import { setTimeout } from 'timers'
import { getPaymentStr } from '../api/api.js'
import { open } from '@/utils/JumpUtils.js'
export default {
  data() {
    return {
      isPhoneNoRecharge: false, // 手机号充值-获取到的支付按钮状态
      isClicked: false, // 支付按钮是否被点击,false表示可点击
      isPayment: true, // 是否获取到支付方式
      skuid: '', // SKUid获取
      salePrice: '' // 支付金额
    }
  },
  methods: {
    // 获取支付方式
    getPaymentMethod(paymentType) {
      this.paymentType = paymentType
    },
    getPhoneNum() {
      return null
    },
    // 调起支付
    comfirmPay() {
      // 输入的手机号为空/不符合，点击支付按钮则不发送协议
      if (this.isPhoneNoRecharge) {
        return false
      }
      // 手机号符合并验证通过，点击按钮则正常发送协议
      if (!this.isClicked && this.isPayment) {
        this.isClicked = true
        setTimeout(() => {
          this.isClicked = false
        }, 3000)
        // let fontUrl = ''
        // if (this.paymentType === 'JINHUA_CHENGTAI') {
        //   fontUrl = 'xbapp://goback/buscard-app/recharge.html'
        // } else {
        //   fontUrl = `${window.online_paysuccess_page}?stype=3`
        // }
        let fontUrl = window.getWapPayCallbackUrl(this.paymentType, 1, 6, 'buscard-app/recharge.html')
        getPaymentStr(
          this.skuid,
          this.paymentType,
          this.getPhoneNum(),
          this.couponsId,
          this.salePrice,
          this.cardNo,
          this.cardType,
          0,
          fontUrl).then(res => {
          // switch (this.paymentType) {
          //   // 插件支付（微信、支付宝）
          //   case 'ALIPAY':
          //   case 'WXPAY':
          //   case 'WXJSPAY':
          //     this.$doPayment(
          //       this.paymentType,
          //       res.paymentStr,
          //       () => {
          //         let paramstr = `&_bbv=false&number=${res.orderId}`
          //         go(`module=buscard-app&page=paySuccess&_tv=true${paramstr}`)
          //         open('rechargesuccess.html?orderId=' + res.orderId)
          //       },
          //       err => {
          //         this.isClicked = false
          //         console.dir(err)
          //       })
          //     break
          //     // 银联、诚泰
          //   case 'UNIONPAY_WAP':
          //   case 'JINHUA_CHENGTAI':
          //     // 存储订单编号和支付串后，再跳入中转页
          //     window.localStorage.setItem('TRADE_ID_jdlfa12', res.orderId)
          //     window.localStorage.setItem('PAYJUMPFORM', res.paymentStr)
          //     goByUsualUrl(window.pay_mid_page)
          //     open('rechargesuccess.html?orderId=' + res.orderId)
          //     break
          // }
          // console.log('订单编号：' + res.orderId)
          window.localStorage.setItem('TRADE_ID_jdlfa12', res.orderId)
          window.doPaymentByType(this.paymentType, res.paymentStr, () => {
            open('rechargesuccess.html?orderId=' + res.orderId)
          }, err => {
            this.isClicked = false
            console.dir(err)
          })
        }).catch(err => {
          this.isClicked = false
          console.dir(err)
        })
      }
    }
  }
}
</script>
